﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace HRN.Bot {
    class UrlHistory {
        protected string _url;
        public string Url {
            get { return _url; }
            set { _url = value; }
        }


        protected List<ProxyHistory> _proxies;
        public List<ProxyHistory> Proxies {
            get { return _proxies; }
            set { _proxies = value; }
        }
        public int ReqCount {
            get {
                if (_proxies != null)
                    return _proxies.Count;
                else
                    return 0;
            }
        }
        public void Add(string proxy) {
            if (_proxies == null) {
                _proxies = new List<ProxyHistory>();
                CreateProxyHistory(proxy);
            } else {
                int counter = 0;
                foreach (ProxyHistory item in _proxies) {
                    if (proxy == item.Proxy) {
                        item.ClickCount += 1;
                        counter++;
                    }
                }
                if (counter <= 0) 
                    CreateProxyHistory(proxy);
            }

        }
        public void CreateProxyHistory(string proxy) {
            ProxyHistory proxyHistory = new ProxyHistory();
            proxyHistory.Proxy = proxy;
            proxyHistory.ClickCount = 1;
            _proxies.Add(proxyHistory);
        }
        internal bool HasProxyInUrl(List<UrlHistory> urlHistoryList, string url, string proxy) {
            foreach (UrlHistory item in urlHistoryList) {
                if (item.Url == url && item.ReqCount > 0) {
                    foreach (ProxyHistory itemproxy in item.Proxies)
                        if (itemproxy.Proxy == proxy) { return true;}
                }
            }
            return false;
        }

    }
}
